package models;

import java.util.ArrayList;

public class Buff {
	
	private ArrayList<Effect> effects;
	private String name;
	private int ticks_left;
	private boolean hasFaded;
	private Character target;
	
	public Buff(ArrayList<Effect> effects, String name, int duration, Character target) {
		this.effects = effects;
		this.name = name;
		this.ticks_left = duration;
		hasFaded = false;
		this.target = target;
	}

	public synchronized ArrayList<Effect> getEffects() {
		return effects;
	}

	public synchronized void tick() {
		System.out.println(name + " ticked!");
		if(!hasFaded)
			this.ticks_left--;
		if(ticks_left <= 0) {
			hasFaded = true;
			System.out.println(name + " faded!");
		}
	}
	
	public boolean hasFaded() {
		return hasFaded;
	}
	
	public String getName() {
		return name;
	}

	public Character getTarget() {
		return target;
	}

	public synchronized void setTarget(Character target) {
		this.target = target;
	}
	
	public String toString() {
		String temp = this.name;
		for(Effect e : effects) {
			temp = temp + "\n-" + e.getStat() + " " + e.getAmmount();
		}
		return temp;
	}
	
}
